persistent database connection - Apache::DBI with mod_perl

persistent database connection - Apache::DBI with mod_perl

am 16.07.2008 07:58:19 von Chris Zhuang

--0-1480779522-1216187899=:73831
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi,
 
I have problems to setup persistent database connection for my perl project=
using mod_perl.
 
It tooks me two days which i still cann't figure out how mod_perl works wit=
h Apache::DBI.
 
My Server Settings:
ActiveState Perl 5.8.8 build 822
Apache HTTP Server 2.2.9
Apache DBI 1.06
mod_perl 2.03
DBD-Oracle 1.17
 
--------------Adding to httpd.conf--------------
 
LoadFile "C:/Perl/bin/perl58.dll"
LoadModule perl_module modules/mod_perl.so
PerlSetEnv DBI_TRACE "3=3DC:/Perl/dbitrace.log"
PerlModule Apache::DBI
PerlRequire  "C:/Perl/lib/startup.pl"
 
--------------End-------------------------------------
 
--------------startup.pl--------------
#!c:/perl/bin/perl.exe=20

$ENV{MOD_PERL} or die "GATEWAY_INTERFACE not Perl!";
#use Apache::Registry;
use Apache::DBI;
use strict;

$Apache::DBI::DEBUG =3D 2;

Apache::DBI->connect_on_init("dbi:Oracle:host=3Dxxx;sid=3Dxx x",
             =C2=
 Â Â Â Â Â Â Â Â Â Â  Â Â=A0=
    "xxx", "xxx",
             =C2=
 Â Â Â Â Â Â Â Â Â Â  Â Â=A0=
    {PrintError =3D> 1, RaiseError =3D> 0, AutoCommit =3D> 1=
,}
             =C2=
 Â Â Â Â Â Â Â Â Â Â  Â Â=A0=
    );
 
my $timeout =3D 0;
Apache::DBI->setPingTimeOut("dbi:Oracle:host=3Dxxx;sid=3Dxxx ", $timeout);
 
1;
--------------End-------------------------------------
 
--------------Apache Startup Log-------------------------------------
[Wed Jul 16 14:43:54 2008] [notice] Apache/2.2.9 (Win32) mod_perl/2.0.3 Per=
l/v5.8.8 configured -- resuming normal operations
[Wed Jul 16 14:43:54 2008] [notice] Server built: Jun 13 2008 04:04:59
[Wed Jul 16 14:43:54 2008] [notice] Parent: Created child process 996
[Wed Jul 16 14:43:54 2008] [notice] Child 996: Child process is running
996 Apache::DBI        = C2 Â=A0=
   PerlChildInitHandler
996 Apache::DBI        = C2 Â=A0=
   need ping: yes
996 Apache::DBI        = C2 Â=A0=
   new connect to 'host=3Dxxx;sid=3Dxxx=1Cxxx=1Cxxx=1CAutoCommit=
=3D1=1CPrintError=3D1=1CRaiseError=3D0=1CUsername=3Dxxx'
[Wed Jul 16 14:43:55 2008] [notice] Child 996: Acquired the start mutex.
[Wed Jul 16 14:43:55 2008] [notice] Child 996: Starting 64 worker threads.
[Wed Jul 16 14:43:55 2008] [notice] Child 996: Starting thread to listen on=
port 80.
--------------End-------------------------------------
I can see it sucessful open the oracle DB connection.
 
However, when I run an CGI script on the IE 6, it cannot find $ENV{MOD_PERL=
} and start new DBI connection.
 
--------foo.cgi--------------------
#!c:/perl/bin/perl.exe -d
use DBI;
use CGI qw(:standard);

my $dbh =3D DBI->connect("dbi:Oracle:host=3Dxxx;sid=3Dxxx",
             =C2=
 Â Â Â Â Â Â Â Â Â Â  Â Â=A0=
    "xxx", "xxx",
             =C2=
 Â Â Â Â Â Â Â Â Â Â  Â Â=A0=
    {PrintError =3D> 1, RaiseError =3D> 0, AutoCommit =3D> 1=
,}
             =C2=
 Â Â Â Â Â Â Â Â Â Â  Â Â=A0=
    );
--------END--------------------
 
Do I need to do any setting in Apache for $ENV{MOD_PERL}?=20
Did I do any thing wrong in above code?
 
Thanks and Regards
 
Chris Z =0A Start at the new Yahoo!7 for a better online experien=
ce. www.yahoo7.com.au
--0-1480779522-1216187899=:73831
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

top' style=3D'font: inherit;'>

Hi,


 


I have problems to setup persistent database connection for my perl proj=
ect using mod_perl.


 


It tooks me two days which i still cann't figure out how mod_perl works =
with Apache::DBI.


 


My Server Settings:


ActiveState Perl 5.8.8 build 822


Apache HTTP Server 2.2.9


Apache DBI 1.06


mod_perl 2.03


DBD-Oracle 1.17


 


--------------Adding to httpd.conf--------------


 


LoadFile "C:/Perl/bin/perl58.dll"
LoadModule perl_module modules/mod_=
perl.so
PerlSetEnv DBI_TRACE "3=3DC:/Perl/dbitrace.log"
PerlModule Ap=
ache::DBI
PerlRequire  "C:/Perl/lib/startup.pl"


 


--------------End-------------------------------------


 


--------------startup.pl--------------


#!c:/perl/bin/perl.exe



$ENV{MOD_PERL} or die "GATEWAY_INTERFACE not Perl!";


#use Apache::Registry;
use Apache::DBI;
use strict;



$Apache::DBI::DEBUG =3D 2;



Apache::DBI->connect_on_init("dbi:Oracle:host=3Dxxx;sid=3Dxxx", R>            &=
nbsp;           &nbs=
p;    "xxx", "xxx",
      &=
nbsp;           &nbs=
p;          {PrintError =3D>=
; 1, RaiseError =3D> 0, AutoCommit =3D> 1,}
   &nbs=
p;            &=
nbsp;            );<=
/P>

 


my $timeout =3D 0;


Apache::DBI->setPingTimeOut("dbi:Oracle:host=3Dxxx;sid=3Dxxx", $timeo=
ut);


 


1;


--------------End-------------------------------------


 


--------------Apache Startup Log------------------------------------- >

[Wed Jul 16 14:43:54 2008] [notice] Apache/2.2.9 (Win32) mod_perl/2.0.3 =
Perl/v5.8.8 configured -- resuming normal operations
[Wed Jul 16 14:43:5=
4 2008] [notice] Server built: Jun 13 2008 04:04:59
[Wed Jul 16 14:43:54=
2008] [notice] Parent: Created child process 996
[Wed Jul 16 14:43:54 2=
008] [notice] Child 996: Child process is running
996 Apache::DBI &=
nbsp;           PerlChild=
InitHandler
996 Apache::DBI       &nb=
sp;     need ping: yes
996 Apache::DBI  &n=
bsp;          new connect to '=
host=3Dxxx;sid=3Dxxx=1Cxxx=1Cxxx=1CAutoCommit=3D1=1CPrintErr or=3D1=1CRaiseE=
rror=3D0=1CUsername=3Dxxx'
[Wed Jul 16 14:43:55 2008] [notice] Child 996=
: Acquired the start mutex.
[Wed Jul 16 14:43:55 2008] [notice] Child 99=
6: Starting 64 worker threads.
[Wed Jul 16 14:43:55 2008] [notice] Child=
996: Starting
thread to listen on port 80.


--------------End-------------------------------------


I can see it sucessful open the oracle DB connection.


 


However, when I run an CGI script on the IE 6, it cannot find $ENV{MOD_P=
ERL} and start new DBI connection.


 


--------foo.cgi--------------------


#!c:/perl/bin/perl.exe -d
use DBI;
use CGI qw(:standard);



my $dbh =3D DBI->connect("dbi:Oracle:host=3Dxxx;sid=3Dxxx",
&n=
bsp;            =
;            &n=
bsp;   "xxx", "xxx",
       =
;            &n=
bsp;         {PrintError =3D> 1,=
RaiseError =3D> 0, AutoCommit =3D> 1,}
    &n=
bsp;            =
;            );


--------END--------------------


 


Do I need to do any setting in Apache for $ENV{MOD_PERL}?


Did I do any thing wrong in above code?


 


Thanks and Regards


 


Chris Z



=0AStart=
at the new Yahoo!7 for a better online experience - d.yahoo.com/mail/taglines/au/y7mail/default/*http://au.docs. yahoo.com/somet=
hingwonderful/index.php?p1=3Dbrand&p2=3Dother&p3=3Dau&p4=3Dt agline" target=
=3D_blank>Start Here
.
--0-1480779522-1216187899=:73831--

Re: persistent database connection - Apache::DBI with mod_perl

am 16.07.2008 16:33:07 von Adam Prime

Quoting Chris Zhuang :

> Hi,
> However, when I run an CGI script on the IE 6, it cannot find
> $ENV{MOD_PERL} and start new DBI connection.
> --------foo.cgi--------------------
> #!c:/perl/bin/perl.exe -d
> use DBI;
> use CGI qw(:standard);
>
> my $dbh = DBI->connect("dbi:Oracle:host=xxx;sid=xxx",
> "xxx", "xxx",
> {PrintError => 1, RaiseError => 0,
> AutoCommit => 1,}
> );
> --------END--------------------
>

It looks like your CGI's are are running under CGI, not
ModPerl::PerlRun, or ModPerl::Registry.

see:
http://perl.apache.org/docs/2.0/user/intro/start_fast.html#R egistry_Scripts

Re: persistent database connection - Apache::DBI with mod_perl

am 17.07.2008 05:04:07 von Chris Zhuang

--0-661032591-1216263847=:33423
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi adam,
 
I got that mod_perl works on my server.
 
But how to setup Komodo 3.1 to debug mod_perl?
 
It seems like Komodo can only debug mod_cgi.
 
My httpd.conf setting:
 

  use lib qw("C:/Program Files/ActiveState Komodo 3.1/dbgp/perllib");
  $ENV{PERLDB_OPTS} =3D "RemotePort=3D127.0.0.1:1417 LogFile=3Dstderr"=
;
  use Apache::DB ();
  Apache::DB->init;

 
Alias /perl/ "C:/Apache2.2/htdocs/perl/"

  SetHandler perl-script
  PerlHandler ModPerl::Registry
  Options +ExecCGI
  PerlOptions +ParseHeaders
  PerlFixupHandler Apache::DB
  Order allow,deny
  Allow from all=20


Below is Apache error logs:
 
Thu Jul 17 12:50:21 2008] [error] Unable to get Terminal Size. The Win32 Ge=
tConsoleScreenBufferInfo call didn't work. The COLUMNS and LINES environmen=
t variables didn't work. The resize program didn't work. at C:/Perl/lib/Ter=
m/ReadKey.pm line 362.\nCompilation failed in require at C:/Perl/lib/Term/R=
eadLine/Perl.pm line 64.\n at C:/Perl/lib/Term/ReadLine/Perl.pm line 64\n\t=
eval {...} called at C:/Perl/lib/Term/ReadLine/Perl.pm line 64\n\tTerm::Rea=
dLine::Perl::new('Term::ReadLine', 'perldb', 'IO::Socket::INET=3DGLOB(0xa4f=
9cbc)', 'IO::Socket::INET=3DGLOB(0xa4f9cbc)') called at C:/Perl/site/lib/Ap=
ache/perl5db.pl line 2226\n\tDB::setterm called at C:/Perl/site/lib/Apache/=
perl5db.pl line 773\n\tDB::DB called at C:/Apache2.2/htdocs/perl/foo2.cgi l=
ine 2\n\tModPerl::ROOT::ModPerl::Registry::C_3a_Apache2_2e2_htdo cs_perl_foo=
2_2ecgi::BEGIN() called at C:/Perl/lib/Term/ReadLine/readline.pm line 2\n\t=
eval {...} called at C:/Perl/lib/Term/ReadLine/readline.pm line
2\n\teval 'package ModPerl::ROOT::ModPerl::Registry::C_3a_Apache2_2e2_htdo=
cs_perl_foo2_2ecgi;sub handler {local $0 =3D \\'C:/Apache2.2/htdocs/perl/fo=
o2.cgi\\';\n#line 1 C:/Apache2.2/htdocs/perl/foo2.cgi\n#!c:/perl/bin/perl.e=
xe\r\n  use strict;\r\n  print "Content-type: text/html\\\\n\\\\n=
";\r\n  print "

Environment variables

Re: persistent database connection - Apache::DBI with mod_perl

am 17.07.2008 23:51:06 von Perrin Harkins

On Wed, Jul 16, 2008 at 11:04 PM, Chris Zhuang wrote:
> But how to setup Komodo 3.1 to debug mod_perl?

You should probably ask the Komodo support list about that.
Apache::DB seems to be working.

- Perrin